package com.leetcode.LC;

public class LC832 {
    public int[][] flipAndInvertImage(int[][] A) {

        for (int i = 0; i < A.length; i++) {
            A[i] = transform(A[i]);
        }
        return A;
    }

    public int[] transform(int[] ints) {

        int a = 0, b = ints.length - 1;
        int tmp;
        while (a < b) {
            if (ints[a] != ints[b]) {
                tmp = ints[a];
                ints[a] = ints[b];
                ints[b] = tmp;
            }
            if (ints[a] == 1) {
                ints[a] = 0;
            } else {
                ints[a] = 1;
            }
            if (ints[b] == 1) {
                ints[b] = 0;
            } else {
                ints[b] = 1;
            }

            a++;
            b--;
        }
        if (a == b) {
            if (ints[a] == 1) {
                ints[a] = 0;
            } else {
                ints[a] = 1;
            }
        }
        return ints;
    }

    public static void main(String[] args) {
        for (int[] ints : new LC832().flipAndInvertImage(new int[][]{{1, 1, 0, 0}, {1, 0, 0, 1}, {0, 1, 1, 1}, {1, 0, 1, 0}})) {

            for (int anInt : ints) {
                System.out.print(anInt);
            }
            System.out.println();
        }
    }
}
